﻿using UnityEngine;

namespace HEFramework
{
    public static class SpriteOutlineComponentSystem
    {
        [EntitySystem]
        public class SpriteOutlineComponentAwakeSystem : AwakeSystem<SpriteOutlineComponent>
        {
            protected override void Awake(SpriteOutlineComponent _self)
            {
            }
        }


        public static void SetTarget(this SpriteOutlineComponent _self, GameObject _target)
        {
            if (_self.Target != null && _self.Target.GetInstanceID() == _target.GetInstanceID())
            {
                return;
            }

            _self.Target = _target;
            _self.Renderers = null;
            _self.Renderers = _self.Target.GetComponentsInChildren<SpriteRenderer>();
        }

        public static void SetColor(this SpriteOutlineComponent _self, Color _color)
        {
            if (_self.Renderers == null)
            {
                return;
            }

            if (_self.Renderers.Length <= 0)
            {
                return;
            }

            for (int i = 0; i < _self.Renderers.Length; i++)
            {
                _self.Renderers[i].material.SetColor("_OutlineColor", _color);
            }
        }
    }
}